package org.misalen.web.restful.job;

import org.json.JSONObject;
import org.misalen.web.restful.util.RetrofitUtil;
import org.misalen.web.restful.util.TypedInput;

import rx.Observable;
import rx.functions.Action1;

public class Item {
	public static final String baseRequest = "http://localhost:8080/misalen-web-server/";
//	public static final String baseRequest = "http://47.93.57.192:8081/misalen-web-server/";

	public static final String version = "v1";
	public static String baseUrl = baseRequest + version + "/";

	public static final String mobile = "15032992879";

	public static void main(String[] args) {
		RetrofitUtil.setBaseUrl(baseUrl);
		config();
//		smsCode();
//		userRegistered();
//		login();
//		autoLogin();
//		findPwd();
//		carrierhot();
	}
	
	public static Observable<JSONObject> carrierhot() {
		JSONObject json = new JSONObject();
		Observable<JSONObject> observable = RetrofitUtil.getService().carrierhot(TypedInput.buildJson(json));
		observable. // 结果
		subscribe(new Action1<JSONObject>() {
			@Override
			public void call(JSONObject weatherData) {
				System.out.println(weatherData);
			}
		}, new Action1<Throwable>() {
			@Override
			public void call(Throwable throwable) {
				System.err.println(throwable.getMessage());
			}
		});
		return observable;
	}
	public static Observable<JSONObject> config() {
		JSONObject json = new JSONObject();
		Observable<JSONObject> observable = RetrofitUtil.getService().config(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}
	public static Observable<JSONObject> details() {
		JSONObject json = new JSONObject();
		json.put("userId", "1");
		json.put("videoId", "402881e45dc1c1aa015dc1c1caed0000");
		Observable<JSONObject> observable = RetrofitUtil.getService().details(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}
	public static Observable<JSONObject> complete() {
		JSONObject json = new JSONObject();
		json.put("userId", "1");
		json.put("type", "headrest");
		Observable<JSONObject> observable = RetrofitUtil.getService().complete(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}
	public static Observable<JSONObject> play() {
		JSONObject json = new JSONObject();
		json.put("userId", "1");
		json.put("type", "headrest");
		Observable<JSONObject> observable = RetrofitUtil.getService().play(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}
	public static Observable<JSONObject> newtask() {
		JSONObject json = new JSONObject();
		json.put("type", "headrest");
		json.put("userId", "1");
		Observable<JSONObject> observable = RetrofitUtil.getService().newtask(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}
	public static Observable<JSONObject> redwars() {
		JSONObject json = new JSONObject();
		json.put("videoId", "402881e45dc1c1aa015dc1c1caed0000");
		json.put("userId", "1");
		Observable<JSONObject> observable = RetrofitUtil.getService().redwars(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}

	public static Observable<JSONObject> smsCode() {
		JSONObject json = new JSONObject();
		json.put("mobile", mobile);
		json.put("type", "find-pwd");
		Observable<JSONObject> observable = RetrofitUtil.getService().smsCode(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}

	public static Observable<JSONObject> userRegistered() {
		JSONObject json = new JSONObject();
		json.put("mobile", mobile);
		json.put("smsCode", "653874");
		json.put("password", "123456");
		json.put("userName", "我的用户名");
		json.put("belongCity", "belongCity");
		json.put("ageRange", "ageRange");
		json.put("socialGroup", "socialGroup");
		json.put("imei", mobile);
		Observable<JSONObject> observable = RetrofitUtil.getService().registered(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}

	public static Observable<JSONObject> login() {
		JSONObject json = new JSONObject();
		json.put("mobile", mobile);
		json.put("password", "123456789");
		json.put("imei", mobile);
		Observable<JSONObject> observable = RetrofitUtil.getService().login(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}
	public static Observable<JSONObject> autoLogin() {
		JSONObject json = new JSONObject();
		json.put("mobile", mobile);
		json.put("imei", mobile);
		Observable<JSONObject> observable = RetrofitUtil.getService().autoLogin(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}
	public static Observable<JSONObject> findPwd() {
		JSONObject json = new JSONObject();
		json.put("mobile", mobile);
		json.put("smsCode", "111223");
		json.put("password", "111223");
		Observable<JSONObject> observable = RetrofitUtil.getService().findPwd(TypedInput.buildJson(json));
		observable. // 结果
				subscribe(new Action1<JSONObject>() {
					@Override
					public void call(JSONObject weatherData) {
						System.out.println(weatherData);
					}
				}, new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.err.println(throwable.getMessage());
					}
				});
		return observable;
	}
	
	
}
